package com.ss.android.article.base.feature.search;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.animation.DecelerateInterpolator;

import com.bytedance.article.common.c.JSONObjectWrapper;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.base.feature.splash.SplashAdActivity;
import com.ss.android.article.browser.R;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.newmedia.a.w;
import com.ss.android.newmedia.activity.FragmentActivity;

import org.json.JSONObject;

public class SearchActivity extends FragmentActivity implements p, w {
    private String a;
    private boolean b;
    private com.ss.android.article.base.feature.search.r c;
    private long d;

    public SearchActivity() {

        this.b = false;
        this.d = 0;
    }

    public final void a() {
        long v8 = 100;
        float v7 = 50f;
        JSONObjectWrapper v1 = new JSONObjectWrapper();
        JSONObjectWrapper v2 = v1.put("enter_from", "click_search").put("category_name", "search").put("stay_time", Long.valueOf(System.currentTimeMillis() - this.d)).put("source", this.a);
        String v3 = "query";
        com.ss.android.article.base.feature.search.r v0 = this.c;
        String v0_1 = !android.support.design.a.isTextEmpty(((com.ss.android.article.base.feature.search.a)v0).l) ? ((com.ss.android.article.base.feature.search.a)v0).l : "";
        v2.put(v3, v0_1);
        android.support.design.a.onEvent("stay_page_search", v1.jo);
        if("detail".equals(this.a)) {
            v0 = this.c;
            q v1_1 = new q(this);
            v0.q.animate().translationY(UIUtils.dp2px(v0.a, v7)).alpha(0f).setInterpolator(new DecelerateInterpolator()).setDuration(v8).start();
            v0.p.animate().translationX(UIUtils.dp2px(v0.a, v7)).alpha(0f).setInterpolator(new DecelerateInterpolator()).setDuration(v8).setListener(v1_1).start();
        }
        else {
            this.finish();
        }
    }

    public int getDayBackgroundRes() {
        return R.color.pg;
    }

    public int getLayout() {
        return R.layout.fragment_activity;
    }

    public int getNightBackgroundRes() {
        return R.color.ph;
    }

    public void init() {
        JSONObject v8_1;
        long v4 = 0;
        super.init();
        this.mRootView.setBackgroundResource(this.getDayBackgroundRes());
        this.mTitleView.setText(com.ss.android.article.browser.R.string.title_search);
        this.mTitleBar.setVisibility(View.GONE);
        this.c = new com.ss.android.article.base.feature.search.r();
        if(this.d >= v4) {
            this.d = System.currentTimeMillis();
        }

        Intent v1 = this.getIntent();
        if(v1 != null) {
            this.b = v1.getBooleanExtra("slide_out_left", false);
            String v0 = v1.getStringExtra("keyword");
            String v2 = v1.getStringExtra("searchhint");
            this.a = v1.getStringExtra("from");
            int v3 = v1.getIntExtra("enter_search_from", 0);
            long v6 = v1.getLongExtra("group_id", v4);
            long v8 = v1.getLongExtra("item_id", v4);
            int v10 = v1.getIntExtra("aggr_type", 0);
            String v11 = v1.getStringExtra("homepage_search_suggest");
            Bundle v12 = new Bundle();
            if(!android.support.design.a.isTextEmpty(v11)) {
                v12.putString("homepage_search_suggest", v11);
            }

            if(!android.support.design.a.isTextEmpty(v0)) {
                v12.putString("keyword", v0);
            }

            if(!android.support.design.a.isTextEmpty(v2)) {
                v12.putString("searchhint", v2);
            }

            if(!android.support.design.a.isTextEmpty(this.a)) {
                v12.putString("from", this.a);
            }

            v12.putString("init_from", v1.getStringExtra("init_from"));
            v12.putString("init_category", v1.getStringExtra("init_category"));
            v12.putInt("enter_search_from", v3);
            v12.putLong("group_id", v6);
            v12.putLong("item_id", v8);
            v12.putInt("aggr_type", v10);
            v12.putBoolean("extra_hide_tips", v1.getBooleanExtra("extra_hide_tips", false));
            this.c.setArguments(v12);
            String v3_1 = v1.getStringExtra("growth_from");
            if(android.support.design.a.isTextEmpty(v3_1)) {
            }else {
                JSONObject v0_1 = null;
                String v1_1 = v1.getStringExtra("gd_ext_json");
                if (!android.support.design.a.isTextEmpty(v1_1)) {
                    try {
                        v8_1 = new JSONObject(v1_1);
                    } catch (Exception v1_2) {
                        v8_1 = v0_1;
                    }
                } else {
                    v8_1 = v0_1;
                }
                MobClickCombiner.onEvent(this, "search_detail", v3_1, v4, v4, v8_1);
            }
        }
        FragmentTransaction fragmentTransaction = this.getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(com.ss.android.article.browser.R.id.fragment_container, this.c, "search_fragment");
        fragmentTransaction.commit();
        this.getWindow().setSoftInputMode(2);
    }

    public final void disableOverlaySwipe() {
        if(this.mSwipeOverlay != null) {
            this.mSwipeOverlay.setSwipeEnabled(false);
        }
    }

    public void onBackPressed() {
        Fragment v0 = this.getSupportFragmentManager().findFragmentById(com.ss.android.article.browser.R.id.fragment_container);
        boolean v0_1 = (v0 instanceof com.ss.android.article.base.feature.search.r) ? ((com.ss.android.article.base.feature.search.r)v0).p() : false;
        if(!v0_1) {
            this.a();
        }
    }

    public void onCreate(Bundle savedInstanceState) {
        this.requestDisableOptimizeViewHierarchy();
        super.onCreate(savedInstanceState);
        this.getWindow().setSoftInputMode(48);
    }

    public void onCreateHook() {
    }

    public void onDestroy() {
        super.onDestroy();
    }

    public void onResume() {
        super.onResume();
        SplashAdActivity.a(((Context)this), false);
    }

    public boolean useSwipeRight() {
        boolean v0 = !this.b ? true : false;
        return v0;
    }
}

